package com.health.tablebean.webservice;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tools.ImageTools;
import com.health.viewscontrols.NovaApplication;
import com.health.db.FDbManager;
import com.health.tablebean.CD_DIABETESFOLLOWUP;
import com.health.tablebean.CD_DRUGCONDITION;
import com.health.tablebean.PharmacyList;
import com.health.tools.GlobalConts;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;

/**
 * @author Administrator 糖尿病
 */
public class Diabetes {
	private static final String QXZ = "50%";
	private static final String WZD = "50%";
	private String arteriopalmus; // 足背动脉搏动标志
	private String avoirdupois; // 体重(kg)
	private String cardid; // 居民身份证/健康卡号
	private String compiance; // 遵医行为评价代码
	private String createorg; // 创建机构
	private String creater; // 创建人
	private String createtime; // 创建时间
	private String curSymptom; // 症状代码组合
	private String dependence; // 服药依从性代码
	private String dieresult; // 死亡原因 失访死亡
	private String dietime; // 死亡时间 失访死亡
	private String drink; // 日饮酒量(两)
	private String effectsState; // 药物不良反应描述
	private String fbg; // 空腹血糖值(mmol/L)
	private String happentime;// 随访日期
	private String hgb; // 糖化血红蛋白值(%)
	private String inputMan;// 随访人(随访医生)
	private String insulinDose;// 胰岛素用法和用量
	private String insulinType;// 胰岛素用药种类
	private String lowEffects;// 低血糖反应代码
	private String mentality;// 心理调整
	private String nextVisitDate; // 下次随访日期
	private String otherPositive; // 其他阳性体征
	private String otherSymptom; // 其他症状描述
	private List<PharmacyList> pharmacyList; // dosage 用量
												// drugName 药物名称
												// reg2 用药单位
												// usage 用法
	private String physique; // 体质指数（BMI)
	private String pressureH; // 收缩压
	private String pressureL; // 舒张压
	private String qdqxz; // 缺项值
	private String qjbqk; // 迁往地点基本情况 失访迁出
	private String qjjjl; // 档案交接记录 失访迁出
	private String res0; // 是否吸烟
	private String res1; // 是否饮酒
	private String res2; // 糖化血红蛋白检查日期-月
	private String res3; // 糖化血红蛋白检查日期-日
	private String res4; // 失访原因类型
	private String res5; // 足背动脉搏动 减弱 侧
	private String res6; // 足背动脉搏动 消失 侧
	private String res7; // 失访--具体失访原因（输入）
	private String res8; // 失访--具体失访原因（输入）
	private String rice; // 日主食量(g)
	// private String hpc;// 转诊 原因
	// private String rollInRegion;// 机构及科别
	private Rolloutrollout rollout;
	private String sideEffects;// 药物不良反应标志
	private String smoke; // 日吸烟量（支）
	private String subCheck;// 其他辅助检查描述
	private String targetAvoirdupois;// 目标体重（kg)
	private String targetDrink;// 目标日饮酒量(两）
	private String targetPhysique;// 目标体质指数
	private String targetRice;// 目标日主食量(g)
	private String targetSmoke;// 目标日吸烟量（支）
	private String targetTraining;// 目标运动频率代码
	private String targetTrainingMin;// 目标每次锻炼时间(min)
	private String training; // 运动频率代码
	private String trainingMin; // 每次锻炼时间(min)
	private String visitType;// 随访评价结果代码
	private String visitWay; // 随访方式代码
	private String wzd;// 完整度
	private String fromType = "2";// 数据来源；空为公卫，‘1’为手提箱，‘2’为PAD
	private String updatetime;//修改时间
	private String updateorg;
	private String personalid;

	/**健康评价*/
	private String healthAssess;
	private String stature;//身高
	/**	有无转诊*/
	private String isReferral;//有无转诊   DM01-11_2 有 DM01-11_1 无

	// 是否失访  res5   失访原因res7
//	private String res5;
//	private String res7;
	// 随访类型
	private String visitFollowUpType;
	// 备注
	private String remark;
	// 下一步管理措施
	private String nextManagementMeasures;

	// 联系人及电话
	private String contactsTel;
	// 转诊结果
	private String result;
	private String personSignBase64;
	private String followUpPicBase64;
	private List<PharmacyList> pharmacyAdjustList;

	public List<PharmacyList> getPharmacyAdjustList() {
		return pharmacyAdjustList;
	}

	public void setPharmacyAdjustList(List<PharmacyList> pharmacyAdjustList) {
		this.pharmacyAdjustList = pharmacyAdjustList;
	}

	public String getPersonSignBase64() {
		return personSignBase64;
	}

	public void setPersonSignBase64(String personSignBase64) {
		this.personSignBase64 = personSignBase64;
	}

	public String getFollowUpPicBase64() {
		return followUpPicBase64;
	}

	public void setFollowUpPicBase64(String followUpPicBase64) {
		this.followUpPicBase64 = followUpPicBase64;
	}

	public String getContactsTel() {
		return contactsTel;
	}

	public void setContactsTel(String contactsTel) {
		this.contactsTel = contactsTel;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getRes8() {
		return res8;
	}

	public void setRes8(String res8) {
		this.res8 = res8;
	}

	public String getVisitFollowUpType() {
		return visitFollowUpType;
	}

	public void setVisitFollowUpType(String visitFollowUpType) {
		this.visitFollowUpType = visitFollowUpType;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getNextManagementMeasures() {
		return nextManagementMeasures;
	}

	public void setNextManagementMeasures(String nextManagementMeasures) {
		this.nextManagementMeasures = nextManagementMeasures;
	}

	public String getStature() {
		return stature;
	}

	public void setStature(String stature) {
		this.stature = stature;
	}

	public String getHealthAssess() {
		return healthAssess;
	}

	public void setHealthAssess(String healthAssess) {
		this.healthAssess = healthAssess;
	}

	public String getIsReferral() {
		return isReferral;
	}

	public void setIsReferral(String isReferral) {
		this.isReferral = isReferral;
	}

	public String getPersonalid() {
		return personalid;
	}

	public void setPersonalid(String personalid) {
		this.personalid = personalid;
	}

	public String getUpdateorg() {
		return updateorg;
	}

	public void setUpdateorg(String updateorg) {
		this.updateorg = updateorg;
	}

	public String getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(String updatetime) {
		this.updatetime = updatetime;
	}

	public String getArteriopalmus() {
		return arteriopalmus;
	}

	public void setArteriopalmus(String arteriopalmus) {
		this.arteriopalmus = arteriopalmus;
	}

	public String getAvoirdupois() {
		return avoirdupois;
	}

	public void setAvoirdupois(String avoirdupois) {
		this.avoirdupois = avoirdupois;
	}

	public String getCardid() {
		return cardid;
	}

	public void setCardid(String cardid) {
		this.cardid = cardid;
	}

	public String getCompiance() {
		return compiance;
	}

	public void setCompiance(String compiance) {
		this.compiance = compiance;
	}

	public String getCreateorg() {
		return createorg;
	}

	public void setCreateorg(String createorg) {
		this.createorg = createorg;
	}

	public String getCreater() {
		return creater;
	}

	public void setCreater(String creater) {
		this.creater = creater;
	}

	public String getCurSymptom() {
		return curSymptom;
	}

	public void setCurSymptom(String curSymptom) {
		this.curSymptom = curSymptom;
	}

	public String getDependence() {
		return dependence;
	}

	public void setDependence(String dependence) {
		this.dependence = dependence;
	}

	public String getDieresult() {
		return dieresult;
	}

	public void setDieresult(String dieresult) {
		this.dieresult = dieresult;
	}

	public String getDrink() {
		return drink;
	}

	public void setDrink(String drink) {
		this.drink = drink;
	}

	public String getEffectsState() {
		return effectsState;
	}

	public void setEffectsState(String effectsState) {
		this.effectsState = effectsState;
	}

	public String getFbg() {
		return fbg;
	}

	public void setFbg(String fbg) {
		this.fbg = fbg;
	}

	public String getHgb() {
		return hgb;
	}

	public void setHgb(String hgb) {
		this.hgb = hgb;
	}

	public String getInputMan() {
		return inputMan;
	}

	public void setInputMan(String inputMan) {
		this.inputMan = inputMan;
	}

	public String getInsulinDose() {
		return insulinDose;
	}

	public void setInsulinDose(String insulinDose) {
		this.insulinDose = insulinDose;
	}

	public String getInsulinType() {
		return insulinType;
	}

	public void setInsulinType(String insulinType) {
		this.insulinType = insulinType;
	}

	public String getLowEffects() {
		return lowEffects;
	}

	public void setLowEffects(String lowEffects) {
		this.lowEffects = lowEffects;
	}

	public String getMentality() {
		return mentality;
	}

	public void setMentality(String mentality) {
		this.mentality = mentality;
	}

	public String getOtherPositive() {
		return otherPositive;
	}

	public void setOtherPositive(String otherPositive) {
		this.otherPositive = otherPositive;
	}

	public String getOtherSymptom() {
		return otherSymptom;
	}

	public void setOtherSymptom(String otherSymptom) {
		this.otherSymptom = otherSymptom;
	}

	public List<PharmacyList> getPharmacyList() {
		return pharmacyList;
	}

	public void setPharmacyList(List<PharmacyList> pharmacyList) {
		this.pharmacyList = pharmacyList;
	}

	public String getPhysique() {
		return physique;
	}

	public void setPhysique(String physique) {
		this.physique = physique;
	}

	public String getPressureH() {
		return pressureH;
	}

	public void setPressureH(String pressureH) {
		this.pressureH = pressureH;
	}

	public String getPressureL() {
		return pressureL;
	}

	public void setPressureL(String pressureL) {
		this.pressureL = pressureL;
	}

	public String getQdqxz() {
		return qdqxz;
	}

	public void setQdqxz(String qdqxz) {
		this.qdqxz = qdqxz;
	}

	public String getQjbqk() {
		return qjbqk;
	}

	public void setQjbqk(String qjbqk) {
		this.qjbqk = qjbqk;
	}

	public String getQjjjl() {
		return qjjjl;
	}

	public void setQjjjl(String qjjjl) {
		this.qjjjl = qjjjl;
	}

	public String getRes0() {
		return res0;
	}

	public void setRes0(String res0) {
		this.res0 = res0;
	}

	public String getRes1() {
		return res1;
	}

	public void setRes1(String res1) {
		this.res1 = res1;
	}

	public String getRes3() {
		return res3;
	}

	public void setRes3(String res3) {
		this.res3 = res3;
	}

	public String getRes4() {
		return res4;
	}

	public void setRes4(String res4) {
		this.res4 = res4;
	}

	public String getRes5() {
		return res5;
	}

	public void setRes5(String res5) {
		this.res5 = res5;
	}

	public String getRes6() {
		return res6;
	}

	public void setRes6(String res6) {
		this.res6 = res6;
	}

	public String getRes7() {
		return res7;
	}

	public void setRes7(String res7) {
		this.res7 = res7;
	}

	public String getRice() {
		return rice;
	}

	public void setRice(String rice) {
		this.rice = rice;
	}

	public String getSideEffects() {
		return sideEffects;
	}

	public void setSideEffects(String sideEffects) {
		this.sideEffects = sideEffects;
	}

	public String getSmoke() {
		return smoke;
	}

	public void setSmoke(String smoke) {
		this.smoke = smoke;
	}

	public String getSubCheck() {
		return subCheck;
	}

	public void setSubCheck(String subCheck) {
		this.subCheck = subCheck;
	}

	public String getTargetAvoirdupois() {
		return targetAvoirdupois;
	}

	public void setTargetAvoirdupois(String targetAvoirdupois) {
		this.targetAvoirdupois = targetAvoirdupois;
	}

	public String getTargetDrink() {
		return targetDrink;
	}

	public void setTargetDrink(String targetDrink) {
		this.targetDrink = targetDrink;
	}

	public String getTargetPhysique() {
		return targetPhysique;
	}

	public void setTargetPhysique(String targetPhysique) {
		this.targetPhysique = targetPhysique;
	}

	public String getTargetRice() {
		return targetRice;
	}

	public void setTargetRice(String targetRice) {
		this.targetRice = targetRice;
	}

	public String getTargetSmoke() {
		return targetSmoke;
	}

	public void setTargetSmoke(String targetSmoke) {
		this.targetSmoke = targetSmoke;
	}

	public String getTargetTraining() {
		return targetTraining;
	}

	public void setTargetTraining(String targetTraining) {
		this.targetTraining = targetTraining;
	}

	public String getTargetTrainingMin() {
		return targetTrainingMin;
	}

	public void setTargetTrainingMin(String targetTrainingMin) {
		this.targetTrainingMin = targetTrainingMin;
	}

	public String getTraining() {
		return training;
	}

	public void setTraining(String training) {
		this.training = training;
	}

	public String getTrainingMin() {
		return trainingMin;
	}

	public void setTrainingMin(String trainingMin) {
		this.trainingMin = trainingMin;
	}

	public String getVisitType() {
		return visitType;
	}

	public void setVisitType(String visitType) {
		this.visitType = visitType;
	}

	public String getVisitWay() {
		return visitWay;
	}

	public void setVisitWay(String visitWay) {
		this.visitWay = visitWay;
	}

	public String getWzd() {
		return wzd;
	}

	public void setWzd(String wzd) {
		this.wzd = wzd;
	}

	public String getFromType() {
		return fromType;
	}

	public void setFromType(String fromType) {
		this.fromType = fromType;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public String getDietime() {
		return dietime;
	}

	public void setDietime(String dietime) {
		this.dietime = dietime;
	}

	public String getHappentime() {
		return happentime;
	}

	public void setHappentime(String happentime) {
		this.happentime = happentime;
	}

	public String getNextVisitDate() {
		return nextVisitDate;
	}

	public void setNextVisitDate(String nextVisitDate) {
		this.nextVisitDate = nextVisitDate;
	}

	public String getRes2() {
		return res2;
	}

	public void setRes2(String res2) {
		this.res2 = res2;
	}

	public Rolloutrollout getRollout() {
		return rollout;
	}

	public void setRollout(Rolloutrollout rollout) {
		this.rollout = rollout;
	}

	public static List<Diabetes> convertData(Context context) {
		List<CD_DIABETESFOLLOWUP> datas = FDbManager.getInstance(context).findAllByWhere(CD_DIABETESFOLLOWUP.class,
				"IS_UPDATE is not 'N'" + " AND CREATEORG='" + NovaApplication.getJgbh() + "'");
//		List<CD_DIABETESFOLLOWUP> datas = FDbManager.getInstance(context).findAllByWhere(CD_DIABETESFOLLOWUP.class,
//				"IS_UPDATE='" + "Y'");
		List<Diabetes> wbdatas = new ArrayList<Diabetes>();
		Diabetes wbdata;
		for (CD_DIABETESFOLLOWUP data : datas) {
			if(TextUtils.isEmpty(data.getARCHIVEID())&&TextUtils.isEmpty(data.getIDCARD())){
				continue;
			}
			wbdata = new Diabetes();

			try {
//				wbdata.setRes5(data.getRes11());
				wbdata.setRes8(data.getRes11());
				wbdata.setRes7(data.getRes12());
				wbdata.setVisitFollowUpType(data.getRes13());
				wbdata.setContactsTel(data.getRes14());
				wbdata.setResult(data.getRes15());
				wbdata.setNextManagementMeasures(data.getRes16());
				wbdata.setRemark(data.getRes18());

				if (!TextUtils.isEmpty(data.getRES4())) {
					String base64 = ImageTools.imageToBase64(data.getRES4());
					wbdata.setFollowUpPicBase64("data:image/png;base64," + base64);
				}
				if (!TextUtils.isEmpty(data.getRes17())) {
					String base64 = ImageTools.imageToBase64(data.getRes17());
					wbdata.setPersonSignBase64("data:image/png;base64," + base64);
				}

				List<PharmacyList> drug11 = new ArrayList<>();
				if (!TextUtils.isEmpty(data.getDrug11())) {
					PharmacyList pharmacyList11 = new PharmacyList();
					pharmacyList11.setDrugName(data.getDrug11());
					pharmacyList11.setUsage(data.getDrug12());
					pharmacyList11.setYongfa(data.getDrug12());
					pharmacyList11.setDosage(data.getDrug13());
					pharmacyList11.setReg4(data.getDrug14());
//					pharmacyList11.setReg0(data.getDrug14());
					drug11.add(pharmacyList11);
				}

				if (!TextUtils.isEmpty(data.getDrug21())) {
					PharmacyList pharmacyList21 = new PharmacyList();
					pharmacyList21.setDrugName(data.getDrug21());
					pharmacyList21.setUsage(data.getDrug22());
					pharmacyList21.setYongfa(data.getDrug22());
					pharmacyList21.setDosage(data.getDrug23());
					pharmacyList21.setReg4(data.getDrug24());
//					pharmacyList21.setReg0(data.getDrug24());
					drug11.add(pharmacyList21);
				}

				if (!TextUtils.isEmpty(data.getDrug31())) {
					PharmacyList pharmacyList31 = new PharmacyList();
					pharmacyList31.setDrugName(data.getDrug31());
					pharmacyList31.setUsage(data.getDrug32());
					pharmacyList31.setYongfa(data.getDrug32());
					pharmacyList31.setDosage(data.getDrug33());
					pharmacyList31.setReg4(data.getDrug34());
//					pharmacyList31.setReg0(data.getDrug34());
					drug11.add(pharmacyList31);
				}

				if (!TextUtils.isEmpty(data.getDrug41())) {
					PharmacyList pharmacyList41 = new PharmacyList();
					pharmacyList41.setDrugName(data.getDrug41());
					pharmacyList41.setUsage(data.getDrug42());
					pharmacyList41.setYongfa(data.getDrug42());
					pharmacyList41.setDosage(data.getDrug43());
					pharmacyList41.setReg4(data.getDrug44());
//					pharmacyList41.setReg0(data.getDrug44());
					drug11.add(pharmacyList41);
				}

				wbdata.setPharmacyAdjustList(drug11);
			} catch (Exception e) {
				e.printStackTrace();
			}

			if(TextUtils.isEmpty(data.getDORSALISPEDISPULSE())){
				wbdata.setArteriopalmus("DM01-72_1");
			}else {
				wbdata.setArteriopalmus(data.getDORSALISPEDISPULSE());
			}

			wbdata.setAvoirdupois(data.getWEIGHT());
			wbdata.setStature(data.getHeight());
			if(data.getIDCARD()!=null&&!TextUtils.isEmpty(data.getIDCARD())){
				List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"IDCARD='"+data.getIDCARD()+"'");
				if(ss.size()>0){
					if(!ss.get(0).getPOPULATION_TYPE().contains("7")){
						continue;
					}
				}
				wbdata.setCardid(data.getIDCARD().toUpperCase());
			}else if(!TextUtils.isEmpty(data.getARCHIVEID())){
				List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"ARCHIVEID='"+data.getARCHIVEID()+"'");
				if(ss.size()>0){
					if(!ss.get(0).getPOPULATION_TYPE().contains("7")){
						continue;
					}
					wbdata.setCardid(ss.get(0).getIDCARD().toUpperCase());
				}else{
					wbdata.setCardid("");
				}

			}else{
				wbdata.setCardid("");
			}

			wbdata.setCompiance(data.getOBEYDOCTORBEHAVIOR());
			wbdata.setCreateorg(data.getCREATEORG());
			wbdata.setCreater(data.getCREATER());
			if(data.getCREATED_DATE()!=null){
				wbdata.setCreatetime(GlobalConts.datetimeFormat.format(data.getCREATED_DATE()));
			}else{
				wbdata.setCreatetime(GlobalConts.datetimeFormat.format(new Date()));
			}

			wbdata.setCurSymptom(data.getSYMPTOM());
			wbdata.setHappentime(
					data.getFOLLOWUP_DATE() == null ? "" : GlobalConts.dateFormat.format(data.getFOLLOWUP_DATE()));
			wbdata.setDependence(data.getMEDICATIONCOMPLIANCE());
			// wbdata.setDieresult(dieresult);
			// wbdata.setDietime(dietime);
			wbdata.setDrink(data.getDAILYDRINKNUM());
			if (TextUtils.isEmpty(data.getDAILYDRINKNUM())) {
				wbdata.setRes1("DM01-10_1");// 否饮酒
			} else {
				wbdata.setRes1("DM01-10_2");// 是饮酒
			}
			wbdata.setEffectsState(data.getADR_EX());
			wbdata.setFbg(data.getFPG());
			// wbdata.setFromType(data.get);
			wbdata.setFromType("2");
			wbdata.setHgb(data.getHBALC());
			wbdata.setInputMan(data.getFOLLOWUPDOCTOR());
			wbdata.setInsulinDose(data.getINSULINUSAGE());
			wbdata.setInsulinType(data.getINSULINTYPE());
			wbdata.setLowEffects(data.getHYPOGLYCEMIARREACTION());
			wbdata.setMentality(data.getPSYCHOADJUSTMENT());
			wbdata.setNextVisitDate(data.getNEXTFOLLOWUP_DATE() == null ? ""
					: GlobalConts.dateFormat.format(data.getNEXTFOLLOWUP_DATE()));
			wbdata.setOtherPositive(data.getPHYSICALSYMPTOMOTHER());
			wbdata.setOtherSymptom(data.getSYMPTOMOTHER());
			wbdata.setPhysique(data.getBMI());
			wbdata.setPressureH(data.getHYPERTENSION());
			wbdata.setPressureL(data.getHYPOTENSION());
			wbdata.setIsReferral(data.getISREFERRAL());
			if(!TextUtils.isEmpty(data.getHEALTH_ASSESS())){
				wbdata.setHealthAssess(data.getHEALTH_ASSESS());
			}


			// wbdata.setQjbqk(qjbqk);
			// wbdata.setQjjjl(qjjjl);

			if (data.getEXAMDATE() != null) {
				String format = GlobalConts.dateFormat.format(data.getEXAMDATE());
//				String[] split = format.split("-");
				wbdata.setRes2(format);
//				wbdata.setRes2(split[1]);
//				wbdata.setRes3(split[2]);
//				Log.e("123", "split[1]" + split[1] + "split[2]" + split[2]);
			}

			// wbdata.setRes3(res3);
			// wbdata.setRes4(res4);
			wbdata.setRes5(data.getDORSALISPEDISPULSE_Less());
			wbdata.setRes6(data.getDORSALISPEDISPULSE_Disa());
			// wbdata.setRes7(res7);
			wbdata.setRice(data.getSTAPLEFOODDAILYG());
			wbdata.setSideEffects(data.getADR());
			wbdata.setSmoke(data.getDAILYSMOKENUM());
			if (TextUtils.isEmpty(data.getDAILYSMOKENUM())) {
				wbdata.setRes0("DM01-10_1");// 否吸烟
			} else {
				wbdata.setRes0("DM01-10_2");// 是吸烟
			}
			wbdata.setSubCheck(data.getASSISTANTEXAM());
			wbdata.setTargetAvoirdupois(data.getWEIGHTTARGET());
			wbdata.setTargetDrink(data.getDAILYDRINKNUMTARGET());
			wbdata.setTargetPhysique(data.getBMITARGET());
			wbdata.setTargetRice(data.getSTAPLEFOODDAILYGTARGET());
			wbdata.setTargetSmoke(data.getDAILYSMOKENUMTARGET());
			wbdata.setTargetTraining(data.getSPORTTIMESPERWEEKTARGET());
			wbdata.setTargetTrainingMin(data.getSPORTPERMINUTESTIMETARGET());
			wbdata.setTraining(data.getSPORTTIMEPERWEEK());
			wbdata.setTrainingMin(data.getSPORTPERMINUTETIME());
			wbdata.setVisitType(data.getFOLLOWUPTYPE());
			if (data.getFOLLOWUPWAY().contains("DM04-04")){
				wbdata.setVisitWay(data.getFOLLOWUPWAY().replace("DM04-04","DM04-15"));
			}else{
				wbdata.setVisitWay(data.getFOLLOWUPWAY());
			}
			if(data.getLAST_UPDATE_DATE()!=null){
				wbdata.setUpdatetime(GlobalConts.datetimeFormat.format(data.getLAST_UPDATE_DATE()));
			}


			FDbManager dbm = FDbManager.getInstance(context);
			List<CD_DRUGCONDITION> drs = dbm.findAllByWhere(CD_DRUGCONDITION.class,
					"IDCARD = '" + data.getIDCARD() + "' and TYPE = '2' and PARENTID = '" + data.getID() + "'");
			if (drs != null && !drs.isEmpty()) {
				// wbdata.setPharmacyList(pharmacyList
				List<PharmacyList> phs = new ArrayList<>();
				PharmacyList ph = null;
				for (CD_DRUGCONDITION dr : drs) {
					ph = new PharmacyList();
//					ph.setDosage(dr.getEVERYTIMEMG());
					ph.setDrugName(dr.getNAME());
					if (TextUtils.isEmpty(dr.getRES1())) {	
						ph.setReg2("DM04-05_01");// 默认为mg
					}else{
						ph.setReg2(dr.getRES1());
					}
					ph.setYongfa(dr.getRES3());
					ph.setDosage(dr.getRES4());
//					if(null!=dr.getDAILYTIME()&&""!=dr.getDAILYTIME()){
////						String[] temp = dr.getDAILYTIME().split("/");
//
////						ph.setYongfa(temp[1]);
////						ph.setDosage(temp[0]);
//						String[] temp = dr.getDAILYTIME().split("，");
//						if(temp.length==2){
//							ph.setYongfa(temp[0]);
//							ph.setDosage(temp[1]);
//						}else{
//							ph.setYongfa(dr.getDAILYTIME());
//							ph.setDosage(dr.getDAILYTIME());
//						}
//
//					}
					ph.setReg4(dr.getEVERYTIMEMG()+dr.getRES1());
					ph.setUsage(dr.getDAILYTIME());
					ph.setMedicationTime(dr.getRES2());
					phs.add(ph);

				}
				wbdata.setPharmacyList(phs);
			}else{
				wbdata.setPharmacyList(new ArrayList());
			}
			Rolloutrollout rollout = new Rolloutrollout();
			rollout.setHpc(data.getREFERRALREASON());
			rollout.setRollInRegion(data.getREFERRALORG());
			rollout.setResult(data.getRes15());
			rollout.setContactsTel(data.getRes14());
			wbdata.setRollout(rollout);

			String[] assessIntegrity = GlobalConts.assessIntegrity(wbdata.getArteriopalmus(), wbdata.getAvoirdupois(),
					wbdata.getCompiance(), wbdata.getCurSymptom(), wbdata.getDependence(), wbdata.getFbg(),
					wbdata.getHappentime(), wbdata.getHgb(), wbdata.getInputMan(), wbdata.getLowEffects(),
					wbdata.getMentality(), wbdata.getNextVisitDate(), wbdata.getOtherPositive(), wbdata.getPhysique(),
					wbdata.getPressureH(), wbdata.getRes1(), wbdata.getRice(),
					wbdata.getRollout().getHpc() + wbdata.getRollout().getRollInRegion(), wbdata.getSideEffects(),
					wbdata.getTraining(), wbdata.getVisitType(), wbdata.getVisitWay());

			wbdata.setWzd(assessIntegrity[0]);//
			wbdata.setQdqxz(assessIntegrity[1]);// 
			wbdatas.add(wbdata);
		}

		return wbdatas;
	}

	public static class Rolloutrollout {
		private String hpc;// 转诊 原因
		private String rollInRegion; // 机构及科别
		private String contactsTel; // 到位不到位
		private String result;

		public String getContactsTel() {
			return contactsTel;
		}

		public void setContactsTel(String contactsTel) {
			this.contactsTel = contactsTel;
		}

		public String getResult() {
			return result;
		}

		public void setResult(String result) {
			this.result = result;
		}

		public String getHpc() {
			return hpc;
		}

		public void setHpc(String hpc) {
			this.hpc = hpc;
		}

		public String getRollInRegion() {
			return rollInRegion;
		}

		public void setRollInRegion(String rollInRegion) {
			this.rollInRegion = rollInRegion;
		}

	}

	public class DatabaseHelper extends SQLiteOpenHelper {

		public DatabaseHelper(Context context, String name, CursorFactory factory, int version) {
			super(context, name, factory, version);

		}

		@Override
		public void onCreate(SQLiteDatabase db) {

		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

		}

	}
}